package com.wish.group05.house.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.wish.group05.base.entity.PrivateFacility;
import com.wish.group05.base.entity.PublicFacility;
import com.wish.group05.base.entity.RoomInfo;
import com.wish.group05.base.entity.SysUser;
import com.wish.group05.base.service.IPrivateFacilityService;
import com.wish.group05.base.service.IPublicFacilityService;
import com.wish.group05.base.service.IRoomInfoService;
import com.wish.group05.base.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wish.group05.common.log.annotation.Log;
import com.wish.group05.common.log.enums.BusinessType;
import com.wish.group05.common.security.annotation.PreAuthorize;
import com.wish.group05.common.core.web.controller.BaseController;
import com.wish.group05.common.core.web.domain.AjaxResult;
import com.wish.group05.common.core.utils.poi.ExcelUtil;
import com.wish.group05.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author wish
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/room")
public class TbRoomInfoController extends BaseController
{
    @Autowired
    private IRoomInfoService roomInfoService;

    @Autowired
    private IPrivateFacilityService privateFacilityService;

    @Autowired
    private IPublicFacilityService publicFacilityService;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "house:room:list")
    @GetMapping("/list")
    public TableDataInfo list(RoomInfo tbRoomInfo)
    {
        System.err.println(tbRoomInfo);
        startPage();
        List<RoomInfo> list = roomInfoService.getList(tbRoomInfo);
        return getDataTable(list);
    }

    /**
     * 推荐房源
     */
    @PostMapping("recommend/{id}/{status}")
    public AjaxResult recommend(@PathVariable("id")String id,@PathVariable("status")Integer status) {
        RoomInfo roomInfo = new RoomInfo();
        roomInfo.setId(id);
        roomInfo.setRecommended(status);
        roomInfoService.saveOrUpdate(roomInfo);

        return AjaxResult.success();
    }

    /**
     * 取消推荐房源
     */
    @PostMapping("cancelRecommend/{id}/{status}")
    public AjaxResult cancelRecommend(@PathVariable("id")String id,@PathVariable("status")Integer status) {
        RoomInfo roomInfo = new RoomInfo();
        roomInfo.setId(id);
        roomInfo.setRecommended(status);
        roomInfoService.saveOrUpdate(roomInfo);

        return AjaxResult.success();
    }

    /**
     * 获取私有配套
     * @return
     */
    @GetMapping("getPrivateFacility")
    public AjaxResult getPrivateFacility() {
        List<PrivateFacility> list = privateFacilityService.list();
        return AjaxResult.success(list);
    }

    /**
     * 获取公有配套
     * @return
     */
    @GetMapping("getPublicFacility")
    public AjaxResult getPublicFacility() {
        List<PublicFacility> list = publicFacilityService.list();
        return AjaxResult.success(list);
    }

    /**
     * 获取所有管家
     * @return
     */
    @GetMapping("getSteward")
    public AjaxResult getSteward() {
        List<SysUser> list = sysUserService.list();
        return AjaxResult.success(list);
    }






//    /**
//     * 导出【请填写功能名称】列表
//     */
//    @PreAuthorize(hasPermi = "system:house:export")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TbRoomInfo tbRoomInfo) throws IOException
//    {
//        List<TbRoomInfo> list = tbRoomInfoService.selectTbRoomInfoList(tbRoomInfo);
//        ExcelUtil<TbRoomInfo> util = new ExcelUtil<TbRoomInfo>(TbRoomInfo.class);
//        util.exportExcel(response, list, "info");
//    }

//    /**
//     * 获取【请填写功能名称】详细信息
//     */
//    @PreAuthorize(hasPermi = "system:house:query")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") String id)
//    {
//        return AjaxResult.success(tbRoomInfoService.selectTbRoomInfoById(id));
//    }

//    /**
//     * 新增【请填写功能名称】
//     */
//    @PreAuthorize(hasPermi = "system:house:add")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody TbRoomInfo tbRoomInfo)
//    {
//        return toAjax(tbRoomInfoService.insertTbRoomInfo(tbRoomInfo));
//    }

//    /**
//     * 修改【请填写功能名称】
//     */
//    @PreAuthorize(hasPermi = "system:house:edit")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody TbRoomInfo tbRoomInfo)
//    {
//        return toAjax(tbRoomInfoService.updateTbRoomInfo(tbRoomInfo));
//    }

//    /**
//     * 删除【请填写功能名称】
//     */
//    @PreAuthorize(hasPermi = "system:house:remove")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable String[] ids)
//    {
//        return toAjax(tbRoomInfoService.deleteTbRoomInfoByIds(ids));
//    }
}
